package com.shujia.scala

object Demo11Apply {
  def main(args: Array[String]): Unit = {

    val s1: Score = new Score("001", 100)


    val s2: Score = Score("002", 80)

  }

}


class Score(id: String, sco: Int) {
  val _id: String = id
  val _sco: Int = sco

  override def toString = s"Score(${_id}, ${_sco})"
}

/**
  * 伴生对象
  *
  */
object Score {
  //创建上面类的对象，并返回
  def apply(id: String, sco: Int) = new Score(id, sco)
}